import Vue from 'vue'
import Router from 'vue-router'
import store from '../store'
import Index from '@/pages/home/Index'
import Appointment from '@/pages/appointment/Appointment'
import AppointmentSucc from '@/pages/appointment/AppointmentSucc'
import MyReservation from '@/pages/my-reservation/MyReservation'
import InputNumber from '@/pages/common/InputNumber'
import AppointmentAgain from '@/pages/my-reservation/AppointmentAgain'
import StationQuery from '@/pages/station-query/StationQuery'
import Repairs from '@/pages/repairs/Repairs'
import RepairsSucc from '@/pages/repairs/RepairsSucc'
import SelectLocation from '@/pages/appointment/SelectLocation'
import StationInfo from '@/pages/station-query/StationInfo'
import AppointmentStation from '@/pages/my-reservation/AppointmentStation'
Vue.use(Router)

const router = new Router({
  routes: [
    {
      path: '/index',
      name: 'Index',
      component: Index,
      meta: {
        title: '预约工位'
      }
    },
    {
      path: '/appointment',
      name: 'Appointment',
      component: Appointment,
      meta: {
        title: '预约工位'
      }
    },
    {
      path: '/appointment-succ',
      name: 'AppointmentSucc',
      component: AppointmentSucc,
      meta: {
        title: '预约成功'
      }
    },
    {
      path: '/my-reservation',
      name: 'MyReservation',
      component: MyReservation,
      meta: {
        title: '我的预约'
      }
    },
    {
      path: '/input-number',
      name: 'InputNumber',
      component: InputNumber,
      meta: {
        title: '输入编号'
      }
    },
    {
      path: '/appointment-again',
      name: 'AppointmentAgain',
      component: AppointmentAgain,
      meta: {
        title: '再次预约'
      }
    },
    {
      path: '/station-query',
      name: 'StationQuery',
      component: StationQuery,
      meta: {
        title: '工位查询'
      }
    },
    {
      path: '/repairs',
      name: 'Repairs',
      component: Repairs,
      meta: {
        title: '故障报修'
      }
    },
    {
      path: '/repairs-succ',
      name: 'RepairsSucc',
      component: RepairsSucc,
      meta: {
        title: '报修成功'
      }
    },
    {
      path: '/select-location',
      name: 'SelectLocation',
      component: SelectLocation,
      meta: {
        title: '选择工位'
      }
    },
    {
      path: '/station-info',
      name: 'StationInfo',
      component: StationInfo,
      meta: {
        title: '工位信息'
      }
    },
    {
      path: '/appointment-station',
      name: 'AppointmentStation',
      component: AppointmentStation,
      meta: {
        title: '融创壹号楼'
      }
    },
    {
      path: '/',
      redirect: '/index'
    }
  ],
  scrollBehavior(to, from, savedPosition) {
    return { x: 0, y: 0 }
  }
})

// 路由导航钩子，beforeEach，在路由进入前调用
router.beforeEach((to, from, next) => {
  Vue.prototype.bus.$emit('changeTitle', to.meta.title)
  /* 显示加载中动画 */
  store.commit('updateLoadingStatus', true)
  // 继续路由导航
  next()
})
router.afterEach(route => {
  /* 隐藏加载中动画 */
  store.commit('updateLoadingStatus', false)
})
export default router
